<?php

namespace App\Http\Controllers\Admin\Other;

use App\Services\Admin\Other\SettingService;
use Exception;
use Illuminate\Http\JsonResponse;

class SettingController extends BaseOtherController
{
    protected SettingService $settingService;

    /**
     * @throws Exception
     */
    public function __construct()
    {
        parent::__construct();
        $this->settingService = $this->loadService('Admin\Other\SettingService');
    }


    /**
     * 配置列表
     * @return JsonResponse
     * @throws Exception
     */
    public function list(): JsonResponse
    {

        $list = $this->settingService->list($this->params);
        return outputJsonResult($list);
    }

    /**
     * 更新配置
     * @return JsonResponse
     * @throws Exception
     */
    public function update(): JsonResponse
    {
        $rule = [
            'alias' => 'required|string:min:1',
            'values' => 'required|array|min:1',
        ];
        if ($this->ruleCheck($rule)) {
            return outputJsonResult();
        }

        $this->settingService->update($this->params);

        return outputJsonResult();
    }
}
